package com.iflytek.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.iflytek.entity.Classroom;
import com.iflytek.mapper.ClassroomMapper;
import com.iflytek.query.ClassRoomQuery;
import com.iflytek.service.ClassroomService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.thymeleaf.util.StringUtils;

import javax.annotation.Resource;
import java.util.List;

/**
* @author Administrator
* @description 针对表【classroom】的数据库操作Service实现
* @createDate 2022-09-24 09:36:46
*/
@Service
@Transactional
public class ClassroomServiceImpl extends ServiceImpl<ClassroomMapper, Classroom>
    implements ClassroomService{

    @Resource
    private ClassroomMapper classroomMapper;



    @Override
    public int insertAll(Classroom classroom) {
        if(classroom == null){
            return 0;
        }
        return classroomMapper.insertAll(classroom);
    }

    @Override
    public int update(Classroom classroom) {
        if(classroom == null || classroom.getId() == null){
            return 0;
        }
        return classroomMapper.update(classroom);
    }

    @Override
    public int deleteById(Integer classRoomId) {
        if(classRoomId == null){
            return 0;
        }
        //判断id对应的教室信息是否存在
        Classroom classroom = classroomMapper.getClassRoomById(classRoomId);
        if (classroom == null){
            return 0;
        }
        return classroomMapper.deleteById(classRoomId);
    }

    @Override
    public Classroom getClassRoomById(Integer classRoomId) {
        if(classRoomId == null){
            return null;
        }
        return classroomMapper.getClassRoomById(classRoomId);
    }

    @Override
    public List<Classroom> getClassRoomList(ClassRoomQuery query) {
        return classroomMapper.getClassRoomList(query);
    }

    @Override
    public Classroom getClassRoomByName(String classRoomName) {
        if (StringUtils.isEmpty(classRoomName)){
            return null;
        }
        return classroomMapper.getClassRoomByName(classRoomName);
    }

    @Override
    public Classroom getClassRoomByNo(String classRoomNo) {
        if (StringUtils.isEmpty(classRoomNo)){
            return null;
        }
        return classroomMapper.getClassRoomByNo(classRoomNo);
    }

    @Override
    public int deleteByIds(String[] classRoomIds) {
        if(classRoomIds == null){
            return 0;
        }
        return classroomMapper.deleteByIds(classRoomIds);
    }
}




